package o;

import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.view.View.OnTouchListener;
import android.view.ViewConfiguration;
import android.view.ViewParent;
import huawei.android.widget.DecouplingUtil.ReflectUtil;

public abstract class fpu implements OnTouchListener, OnAttachStateChangeListener {
    private Runnable ʽ;
    protected boolean ˊ;
    private final float ˋ;
    private final View ˎ;
    private final int ˏ = ((this.ॱ + ViewConfiguration.getLongPressTimeout()) / 2);
    private final int ॱ = ViewConfiguration.getTapTimeout();
    private Runnable ॱॱ;
    private int ᐝ;

    class b implements Runnable {
        final /* synthetic */ fpu ˎ;

        private b(fpu o_fpu) {
            this.ˎ = o_fpu;
        }

        public void run() {
            this.ˎ.ˋ();
        }
    }

    class c implements Runnable {
        final /* synthetic */ fpu ˎ;

        private c(fpu o_fpu) {
            this.ˎ = o_fpu;
        }

        public void run() {
            ViewParent parent = this.ˎ.ˎ.getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
        }
    }

    public abstract bt ˏ();

    public fpu(View view) {
        this.ˎ = view;
        view.setLongClickable(true);
        view.addOnAttachStateChangeListener(this);
        this.ˋ = (float) ViewConfiguration.get(view.getContext()).getScaledTouchSlop();
    }

    public boolean onTouch(View view, MotionEvent motionEvent) {
        boolean z;
        boolean z2 = this.ˊ;
        if (!z2) {
            boolean z3 = ˊ(motionEvent) && ˊ();
            if (z3) {
                long uptimeMillis = SystemClock.uptimeMillis();
                MotionEvent obtain = MotionEvent.obtain(uptimeMillis, uptimeMillis, 3, 0.0f, 0.0f, 0);
                this.ˎ.onTouchEvent(obtain);
                obtain.recycle();
            }
            z = z3;
        } else if (ˎ(motionEvent) || !ॱ()) {
            z = true;
        } else {
            z = false;
        }
        this.ˊ = z;
        if (z || z2) {
            return true;
        }
        return false;
    }

    public void onViewAttachedToWindow(View view) {
    }

    public void onViewDetachedFromWindow(View view) {
        this.ˊ = false;
        this.ᐝ = -1;
        if (this.ʽ != null) {
            this.ˎ.removeCallbacks(this.ʽ);
        }
    }

    protected boolean ˊ() {
        bt ˏ = ˏ();
        if (!(ˏ == null || ˏ.ˎ())) {
            ˏ.ˊ();
        }
        return true;
    }

    protected boolean ॱ() {
        bt ˏ = ˏ();
        if (ˏ != null && ˏ.ˎ()) {
            ˏ.ˋ();
        }
        return true;
    }

    private boolean ˊ(MotionEvent motionEvent) {
        View view = this.ˎ;
        if (!view.isEnabled()) {
            return false;
        }
        switch (motionEvent.getActionMasked()) {
            case 0:
                this.ᐝ = motionEvent.getPointerId(0);
                if (this.ʽ == null) {
                    this.ʽ = new c();
                }
                view.postDelayed(this.ʽ, (long) this.ॱ);
                if (this.ॱॱ == null) {
                    this.ॱॱ = new b();
                }
                view.postDelayed(this.ॱॱ, (long) this.ˏ);
                break;
            case 1:
            case 3:
                ˎ();
                break;
            case 2:
                int findPointerIndex = motionEvent.findPointerIndex(this.ᐝ);
                if (findPointerIndex >= 0) {
                    boolean booleanValue;
                    float x = motionEvent.getX(findPointerIndex);
                    float y = motionEvent.getY(findPointerIndex);
                    Object callMethod = ReflectUtil.callMethod(view, "pointInView", new Class[]{Float.TYPE, Float.TYPE, Float.TYPE}, new Object[]{Float.valueOf(x), Float.valueOf(y), Float.valueOf(this.ˋ)}, View.class);
                    if (callMethod != null) {
                        booleanValue = ((Boolean) callMethod).booleanValue();
                    } else {
                        booleanValue = false;
                    }
                    if (!booleanValue) {
                        ˎ();
                        view.getParent().requestDisallowInterceptTouchEvent(true);
                        return true;
                    }
                }
                break;
        }
        return false;
    }

    private void ˎ() {
        if (this.ॱॱ != null) {
            this.ˎ.removeCallbacks(this.ॱॱ);
        }
        if (this.ʽ != null) {
            this.ˎ.removeCallbacks(this.ʽ);
        }
    }

    private void ˋ() {
        ˎ();
        View view = this.ˎ;
        if (view.isEnabled() && !view.isLongClickable() && ˊ()) {
            view.getParent().requestDisallowInterceptTouchEvent(true);
            long uptimeMillis = SystemClock.uptimeMillis();
            MotionEvent obtain = MotionEvent.obtain(uptimeMillis, uptimeMillis, 3, 0.0f, 0.0f, 0);
            view.onTouchEvent(obtain);
            obtain.recycle();
            this.ˊ = true;
        }
    }

    private boolean ˎ(MotionEvent motionEvent) {
        View view = this.ˎ;
        bt ˏ = ˏ();
        if (ˏ == null || !ˏ.ˎ()) {
            return false;
        }
        fpt o_fpt = (fpt) ˏ.ᐝ();
        if (o_fpt == null || !o_fpt.isShown()) {
            return false;
        }
        boolean z;
        MotionEvent obtainNoHistory = MotionEvent.obtainNoHistory(motionEvent);
        ReflectUtil.callMethod(view, "toGlobalMotionEvent", new Class[]{MotionEvent.class}, new Object[]{obtainNoHistory}, View.class);
        ReflectUtil.callMethod(o_fpt, "toLocalMotionEvent", new Class[]{MotionEvent.class}, new Object[]{obtainNoHistory}, View.class);
        boolean ˏ2 = o_fpt.ˏ(obtainNoHistory, this.ᐝ);
        obtainNoHistory.recycle();
        int actionMasked = motionEvent.getActionMasked();
        if (actionMasked == 1 || actionMasked == 3) {
            z = false;
        } else {
            actionMasked = 1;
        }
        if (!ˏ2 || r0 == 0) {
            z = false;
        } else {
            z = true;
        }
        return z;
    }
}
